package com.ocom.mqsimple.controller;

import com.ocom.common.constant.MqSimpleApiUrl;
import com.ocom.common.request.web.ConsumeDetailRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.RandomUtil;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mqsimple.business.consumedetail.ConsumeDetailExportProductService;
import com.ocom.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/8/16
 **/
@Slf4j
@RestController
public class ConsumeDeatilController {

	@Autowired
	ConsumeDetailExportProductService consumeDetailExportProductService;


	@Resource
	RedisUtil redisUtil;

	@PostMapping(MqSimpleApiUrl.URL_consumeDeatilExport)
	public Result consumeDeatilExport(@RequestBody ConsumeDetailRequest request){
		//防止超长mq <250
		String mqKey = "MqSimple:consumeDeatilExport:"+ RandomUtil.getRandomString(20);
		redisUtil.set(mqKey,request,86400l);
		log.info("消费明细导出开始,【{}】",request);
		consumeDetailExportProductService.handle(mqKey);
		return ResultUtil.success();
	}
}
